﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XB.Core.DAO.Audit
{
    public class DefaultPropertyChangeHandler : IPropertyChangeHandler
    {
        private Dictionary<string, ModifiedModel> _modifiedList = new Dictionary<string, ModifiedModel>();

        public List<ModifiedModel> GetModifiedList()
        {
            return _modifiedList == null ? null : _modifiedList.Values.ToList();
        }

        public void Modify(string propertyName, string oldValue, string newValue)
        {
            if (_modifiedList.ContainsKey(propertyName))
            {
                if (_modifiedList[propertyName].OldValue != newValue)
                {
                    _modifiedList[propertyName].NewValue = newValue;
                }
            }
            else
            {
                _modifiedList[propertyName] = new ModifiedModel { NewValue = newValue, OldValue = oldValue, PropertyName = propertyName };
            }
        }
    }
}
